home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Text and Fonts / Drawing Text / GDITEST52.dpr
Encoding:
Text File  |  2003-10-15  |  2.5 KB  |  98 lines

  1. program GDITEST52;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. Procedure OnPaint(DC: HDC);
  11. var
  12.   graphics : TGPGraphics;
  13.   fontFamily: TGPFontFamily;
  14.   font: TGPFont;
  15.   pointF: TGPPointF;
  16.   solidBrush: TGPSolidBrush;
  17. begin
  18.   graphics := TGPGraphics.Create(DC);
  19.   fontFamily:= TGPFontFamily.Create('Times New Roman');
  20.   font := TGPFont.Create(fontFamily, 24, FontStyleRegular, UnitPixel);
  21.   pointF := MakePoint(30.0, 10.0);
  22.   solidBrush:= TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
  23.  
  24.   graphics.DrawString('Hello', -1, font, pointF, solidBrush);
  25.  
  26.   fontFamily.Free;
  27.   font.Free;
  28.   solidBrush.Free;
  29.   graphics.Free;
  30. end;
  31.  
  32.  
  33. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  34. var
  35.   Handle: HDC;
  36.   ps: PAINTSTRUCT;
  37. begin
  38.   case message of
  39.     WM_PAINT:
  40.       begin
  41.         Handle := BeginPaint(Wnd, ps);
  42.         OnPaint(Handle);
  43.         EndPaint(Wnd, ps);
  44.         result := 0;
  45.       end;
  46.  
  47.     WM_DESTROY:
  48.       begin
  49.         PostQuitMessage(0);
  50.         result := 0;
  51.       end;
  52.  
  53.    else
  54.       result := DefWindowProc(Wnd, message, wParam, lParam);
  55.    end;
  56. end;
  57.  
  58. var
  59.   hWnd     : THandle;
  60.   Msg      : TMsg;
  61.   wndClass : TWndClass;
  62. begin
  63.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  64.    wndClass.lpfnWndProc    := @WndProc;
  65.    wndClass.cbClsExtra     := 0;
  66.    wndClass.cbWndExtra     := 0;
  67.    wndClass.hInstance      := hInstance;
  68.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  69.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  70.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  71.    wndClass.lpszMenuName   := nil;
  72.    wndClass.lpszClassName  := 'GettingStarted';
  73.  
  74.    RegisterClass(wndClass);
  75.  
  76.    hWnd := CreateWindow(
  77.       'GettingStarted',       // window class name
  78.       'Drawing Text',       // window caption
  79.       WS_OVERLAPPEDWINDOW,    // window style
  80.       Integer(CW_USEDEFAULT), // initial x position
  81.       Integer(CW_USEDEFAULT), // initial y position
  82.       Integer(CW_USEDEFAULT), // initial x size
  83.       Integer(CW_USEDEFAULT), // initial y size
  84.       0,                      // parent window handle
  85.       0,                      // window menu handle
  86.       hInstance,              // program instance handle
  87.       nil);                   // creation parameters
  88.  
  89.    ShowWindow(hWnd, SW_SHOW);
  90.    UpdateWindow(hWnd);
  91.  
  92.    while(GetMessage(msg, 0, 0, 0)) do
  93.    begin
  94.       TranslateMessage(msg);
  95.       DispatchMessage(msg);
  96.    end;
  97. end.
  98.